#include <stdio.h>
#include "sort.h"
#include "../global.h"

/**
 * 查找pivot值在排序后的正确位置
 * 
 * */
static int PivotIndex(int *nums,int l,int r)
{
	if(nums == NULL) return 0;
	int pivot = nums[l];
	while( l < r)
	{
		while(pivot <= nums[r])
			r--;
		nums[l] = nums[r]; 
		while(l < r && pivot >= nums[l])
			l++;

		nums[r] = nums[l];

	}

	nums[l] = pivot;
	return l;

}

void QuickSort(int *nums,int l,int r)
{
	if(l >= r) return;
	int pivotIndex = PivotIndex(nums,l,r);

	//递归找
	QuickSort(nums,l,pivotIndex-1);
	QuickSort(nums,pivotIndex+1,r);
}



/*
int main(int argc, char const *argv[])
{
	



	return 0;
}

*/
